package com.example.backend.mapper;


import com.example.backend.pojo.User;
import org.apache.ibatis.annotations.*;

import java.time.LocalDateTime;
import java.util.List;

@Mapper
public interface UserMapper {
    @Insert("insert into user (username,password,createtime,updatetime,vip,expiretime,image,state) values (#{username},#{password},now(),now(),0,now(),#{image},1)")
    void add(@Param("username")String username, @Param("password")String password,@Param("image")String image) ;

    @Select("select * from user where username=#{username}")
    User getUserByName(String username);

    @Update("update user set age=#{age},image=#{image},usertypeid=#{usertypeid}, phone=#{phone},gender=#{gender},updatetime=now() where userid=#{userid}")
    void update(User user);

    @Update("update user set image=#{url} ,updatetime=now() where userid=#{id}")
    void updateAvatar(@Param("url")String url,@Param("id)")Integer id);

    @Update("update user set password=#{new_pwd} ,updatetime=now() where userid=#{id}")
    void updatePwd(@Param("id")Integer id, @Param("new_pwd")String new_pwd);

    @Update("update user set expiretime=#{expiretime},vip=1 ,updatetime=now() where userid=#{id}")
    void updatevip(@Param("expiretime")LocalDateTime expiretime, @Param("id")Integer id);

    @Update("update user set state=0,updatetime=now() where userid=#{id}")
    void delete(Integer id);
    @Update("update user set state=1,updatetime=now() where userid=#{id}")
    void relive (Integer id);

    @Select("select * from user ")
    List<User> getall();

    @Select("SELECT restaurantid from foodorder,`user` where  foodorder.userid=`user`.userid  and user.usertypeid=#{usertypeid} GROUP BY restaurantid ORDER BY count(restaurantid) desc")
    List<Integer> ser(Integer usertypeid);

    @Update("update usertype set first=#{first},second=#{second},third=#{third} where usertypeid=#{usertypeid}")
    void updateusertype(@Param("first")Integer first,@Param("second")Integer second,@Param("third")Integer third ,@Param("usertypeid")Integer usertypeid);
    @Update("update user set money=money+#{money} where userid=#{userid} ")
    void updatemoney(Double money,Integer userid);

    @Select("select money from user where  userid=#{userid} ")
    Double getmoney(Integer userid);
}
